package com.pc.ipushpin.common.manager;

import com.pc.ipushpin.business.model.Label;
import com.pc.ipushpin.business.service.ILabelService;
import com.pc.ipushpin.common.util.SignValidator;
import com.pc.ipushpin.common.util.StwConstant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.transaction.Transactional;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class LabelModuleManager {

    @Resource
    private ILabelService labelService;

    private static int pageSize = StwConstant.pageSize;

    private static String imgService = StwConstant.FILE_SERVER_PATH;
    private static String tomcatPath = "/"+ StwConstant.TOMCAT_ROOT;

    private static Logger logger = LoggerFactory.getLogger(LabelModuleManager.class);

    public Map<String,Object> findAllByCompanyId(Map<String, String> mapIn, HttpServletRequest request) {
        logger.info("findAllByLabelIds:"+mapIn);
        Map<String,Object> result = new HashMap<>();

        String companyId = mapIn.get("companyId");
        mapIn.put("companyId", companyId);
        if(!"00".equals(SignValidator.checkEmpty(mapIn).get("resultCode"))){
            return SignValidator.checkEmpty(mapIn);
        }
        List<Label> labels = labelService.findAllByCompanyId(companyId);
        if(labels != null && labels.size() > 0) {
            List<Map<String,Object>> labelMaps = new ArrayList<>();
            for (Label label:labels) {
                Map<String,Object> labelMap = new HashMap<>();
                labelMap.put("name",label.getName());
                labelMap.put("id",label.getId());
                labelMaps.add(labelMap);
            }
            result.put("data",labelMaps);
            result.put("code",200);
        } else {
            result.put("code",400);
        }
        logger.info("findAllByLabelIds result:"+result);
        return result;
    }
}
